package info.motteke.mixivoice4j.http.html;

import info.motteke.mixivoice4j.ImageUrl;
import info.motteke.mixivoice4j.MixiVoiceException;
import info.motteke.mixivoice4j.User;

import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

public class RecentVoiceFavoriteUser implements User {
    private final Element fav;

    public RecentVoiceFavoriteUser(Element fav) {
        this.fav = fav;
    }

    @Override
    public long getId() {
        Elements id = fav.select("input.feedbackMemberId");

        if (id.size() == 0) {
            throw new MixiVoiceException("最新のつぶやきのイイネ！を付けたユーザのIDが取得できません。");
        }

        return Long.parseLong(id.val());
    }

    @Override
    public String getNickName() {
        Elements nickname = fav.select("a.feedbackNickname");

        if (nickname.size() == 0) {
            throw new MixiVoiceException("最新のつぶやきのイイネ！を付けたユーザのニックネームが取得できません。");
        }
        return nickname.get(0).ownText();
    }

    @Override
    public ImageUrl getThumbnail() {
        return null;
    }
}
